package com.kwok.boot.rabbitmq.topics.producer.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    // 创建一个Topic交换机，名称为Topic-Exchange
    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange("Topic-Exchange");
    }

    // 创建两个队列，名称分别为Topics-Queue-One和Topics-Queue-Two
    @Bean
    public Queue queueOne() {
        return new Queue("Topics-Queue-One");
    }

    @Bean
    public Queue queueTwo() {
        return new Queue("Topics-Queue-Two");
    }

    // 绑定队列到交换机
    @Bean
    public Binding bindingOne() {
        // # 表示多个字符 例如：abc.topic.def 不符合 topic.a和topic.a.b 符合
        return BindingBuilder.bind(queueOne()).to(topicExchange()).with("topic.#");
    }

    @Bean
    public Binding bindingTwo() {
        // * 表示单个字符 例如：abc.topic.def 符合 a.b.topic.c.d 不符合
        return BindingBuilder.bind(queueTwo()).to(topicExchange()).with("*.topic.*");
    }

}
